﻿void Merage(int *a,int *b,int low,int mid,int high) {
	int i = low, j = mid,k = low;
	for ( k = low;k <= high;k++) {
		b[k] = a[k];
	}
	for ( i = low, j = mid+1, k = i;i <= mid && j <= high;k++) {
		if (b[i] < b[j]) {
			a[k] = b[i++];
		}
		else
		{
			a[k] = b[j++];
		}
	}
	while (i <= mid) a[k++] = b[i++];
	while (j <= high) a[k++] = b[j++];
}

void MerageAct(int* a, int* b, int low, int high) {
	if (low < high) {
		int min = (high + low) / 2;
		MerageAct(a,b, low, min);
		MerageAct(a,b,min + 1, high);
		Merage(a, b,low, min, high);
	}
}

void MerageSort(int *a, int low, int high) {
	int* b = new int[high];
	MerageAct(a, b, low, high);
	delete[] b;
}

